package com.nlgc365.designpattern.Chapter04_Pattern.Behavior.P05_State.Branch;

import com.nlgc365.designpattern.Chapter04_Pattern.Behavior.P05_State.Framework.State;

/**
 * 作用: 事件以及事件之后的状态改变与动作
 * 问题总结: 这种有限状态机的写法会造成可读性, 可维护性较差, 并且在开发的过程中有可能写错或者写漏条件
 */
public class MarioStateMachine {
    private int score;
    private State currentState;

    /**
     * 构造函数: 设定实例的初始化状态
     */
    public MarioStateMachine() {
        this.currentState = State.SMALL;
        this.score = 0;
    }

    /**
     * 函数: 动作 - 获得蘑菇
     */
    public void obtainMushRoom() {
        this.currentState = State.SUPER;
        this.score += 100;
    }

    /**
     * 函数: 动作 - 获得披风
     */
    public void obtainCape() {
        if (this.currentState.equals(State.SMALL)) {
            this.score += 200;
        } else if (this.currentState.equals(State.SUPER)) {
            this.score += 200;
        }
        this.currentState = State.CAPE;
    }

    /**
     * 函数: 动作 - 获得火焰
     */
    public void obtainFireFlower() {
        if (this.currentState.equals(State.SMALL)) {
            this.score += 300;
        } else if (this.currentState.equals(State.SUPER)) {
            this.score += 300;
        }
        this.currentState = State.FIRE;
    }

    /**
     * 函数: 动作 - 遇到怪物
     */
    public void meetMonster() {
        if (this.currentState.equals(State.SUPER)) {
            this.score -= 100;
        } else if (this.currentState.equals(State.CAPE)) {
            this.score -= 200;
        } else if (this.currentState.equals(State.CAPE)) {
            this.score -= 300;
        }
        this.currentState = State.SMALL;
    }

    public int getScore() {
        return this.score;
    }

    public State getCurrentState() {
        return this.currentState;
    }
}
